﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace JCFramework.Common
{
    public class LinkFinder
    {
        private static Regex s_finder = new Regex("(https?://[^ ]+)");

        public static string FindFirstLink(string msg)
        {
            var match = s_finder.Match(msg);
            if (match.Success)
                return match.Value;

            return String.Empty;
        }

        public static IEnumerable<String> FindAllLink(string msg)
        {
            var matchs = s_finder.Match(msg);
            if (matchs.Success)
            {
                var result = new List<string>();
                for (int i = 1; i <= matchs.Groups.Count; i++)
                {
                    result.Add(matchs.Groups[i].Value);
                }

                return result;
            }

            return null;
        }
    }
}
